//axios二次封装  添加TS
import  axios ,{type AxiosRequestConfig, type AxiosResponse} from 'axios'
import {type IHttp} from '../models'

//地址
axios.defaults.baseURL = `http://127.0.0.1:3000/`;

//请求拦截器
axios.interceptors.request.use((config:AxiosRequestConfig | any)=>config);

//响应拦截器
axios.interceptors.response.use(
    (res:AxiosResponse |any)=>res,
    (err:string)=>Promise.reject(err)
);

//定义一个对象，传入请求参数，返回axios

const http:IHttp = {
    request(method,url,params){
        return axios({
            method:method,
            url:url,
            data:params
        })
    }
}

export default http;


